package com.zzyl.nursing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.nursing.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.NursingService;
import com.zzyl.nursing.service.INursingServiceService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 护理项目Controller
 *
 * @author ityu
 * @date 2025-10-14
 */
@Api(tags ="护理项目管理")
@RestController
@RequestMapping("/serve/project")
public class NursingServiceController extends BaseController
{
    @Autowired
    private INursingServiceService nursingServiceService;

    /**
     * 查询护理项目列表
     */
    @PreAuthorize("@ss.hasPermi('serve:project:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询护理项目列表")
    public TableDataInfo list(NursingService nursingService)
    {
        startPage();
        List<NursingService> list = nursingServiceService.selectNursingServiceList(nursingService);
        return getDataTable(list);
    }

    /**
     * 导出护理项目列表
     */
    @PreAuthorize("@ss.hasPermi('serve:project:export')")
    @Log(title = "护理项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NursingService nursingService)
    {
        List<NursingService> list = nursingServiceService.selectNursingServiceList(nursingService);
        ExcelUtil<NursingService> util = new ExcelUtil<NursingService>(NursingService.class);
        util.exportExcel(response, list, "护理项目数据");
    }

    /**
     * 获取护理项目详细信息
     */
    @ApiOperation(value = "获取护理项目详细信息")
    @PreAuthorize("@ss.hasPermi('serve:project:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(nursingServiceService.selectNursingServiceById(id));
    }

    /**
     * 新增护理项目
     */
    @ApiOperation(value = "新增护理项目")
    @PreAuthorize("@ss.hasPermi('serve:project:add')")
    @Log(title = "护理项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NursingService nursingService)
    {
        return toAjax(nursingServiceService.insertNursingService(nursingService));
    }

    /**
     * 修改护理项目
     */
    @ApiOperation(value = "修改护理项目")
    @PreAuthorize("@ss.hasPermi('serve:project:edit')")
    @Log(title = "护理项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NursingService nursingService)
    {
        return toAjax(nursingServiceService.updateNursingService(nursingService));
    }

    /**
     * 删除护理项目
     */
    @ApiOperation(value = "删除护理项目")
    @PreAuthorize("@ss.hasPermi('serve:project:remove')")
    @Log(title = "护理项目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(nursingServiceService.deleteNursingServiceByIds(ids));
    }

    @GetMapping("/all")
    public AjaxResult getAll() {
        List<NursingProjectVo> list = nursingServiceService.getAll();
        return success(list);
    }
}
